﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Superstore.Store.App_Code
{
    public class WXInfoCacheMgr
    {
        //private static string OPENID_KEY = "FromUserName";
        private static string GPS_LAT_SUF = "Latitude";
        private static string GPS_LOG_SUF = "Longitude";
        private static int GPS_TIMES_INTERVAl = 5;

        private static string openId = "";

        public static void SetOpenID(string openid)
        {
            openId = openid;
            //CommonCacheHelper.SetCache(OPENID_KEY, openid);
        }

        public static string GetOpenID()
        {
            return openId;
            //return Convert.ToString(CommonCacheHelper.GetCache(OPENID_KEY));
        }

        public static void SetLatitude(double latitude)
        {
            string latKey = openId + GPS_LAT_SUF;
            CommonCacheHelper.SetCache(latKey, latitude, DateTime.MaxValue, TimeSpan.FromSeconds(GPS_TIMES_INTERVAl));
        }

        public static double GetLatitude()
        {
            string latKey = openId + GPS_LAT_SUF;
            return Convert.ToDouble(CommonCacheHelper.GetCache(latKey));
        }

        public static void SetLongitude(double longitude)
        {
            string logKey = openId + GPS_LOG_SUF;
            CommonCacheHelper.SetCache(logKey, longitude, DateTime.MaxValue, TimeSpan.FromSeconds(GPS_TIMES_INTERVAl));
        }

        public static double GetLongitude()
        {
            string logKey = openId + GPS_LOG_SUF;
            return Convert.ToDouble(CommonCacheHelper.GetCache(logKey));
        }
    }
}